define(['app','pagination','datetime','editor'], function( appCRM ) {
	'use strict';
	/*资源分配统计控制器*/
	appCRM.controller('Analysis', function($scope, dataFactoryCRM, $q) {
		$scope.analysislistpage = {pageAll: 1,pageNow: 1, pageSize:7,k: 3};
		$scope.analysis_list;

		/**
	     * 获取资源分配信息
	     * @return {[type]} [description]
	     */

	     $scope.switchType = function(ids) {
	     	if(ids) $scope.ids = ids;
	     	$scope.getAnalysisList();
	     };

	     $scope.getAnalysisList = function(){
	     	$scope.begintime = document.getElementById('begintime').value;
    		$scope.endtime = document.getElementById('endtime').value;
	     	var ids = $scope.ids;
	     	if(ids && ids==1){	//部门列表
	     		$("#sector_header").show();
	     		$("#user_header").hide();
	     	}else if(ids && ids==2){	//个人列表
	     		$("#sector_header").hide();
	     		$("#user_header").show();
	     	}
	     	var _url = 'analysis/index?ids='+$scope.ids+'&begintime='+$scope.begintime+'&endtime='+$scope.endtime;
	     		_url += '&p=' + $scope.analysislistpage.pageNow + '&psize=' + $scope.analysislistpage.pageSize;
	     	$scope.$emit("BUSY");
	     	dataFactoryCRM.getDataByAPI(_url).then(function(_d){
	     		if(_d.rcode == "2"){ 	//没有数据
	                $("#y_analysis_list").hide();
	                $("#analysis_listpage").hide(); //分页
	                $("#w_analysis_list").show();
	            }else if(_d.rcode == "1"){	
	                $("#y_analysis_list").show();
	                $("#w_analysis_list").hide();
	                $scope.analysislistpage.pageSize = _d.psize;
	                $scope.analysislistpage.pageAll = _d.pall;
	                $scope.analysislistpage.pageNow = _d.p;
	                $scope.analysis_list = _d.analysis_list;
	                $("#analysis_listpage").show(); //分页	           
	            }
	            $scope.$emit("NOTBUSY");
	     	});
	     }
	    $scope.switchType(1);
	    /*
		* 搜索事件
	    */
	    $scope.search = function(){
	    	$scope.switchType($scope.ids);
	    }
	});
});